<?php
/**
 * <li>Title: account.php</li>
 * <li>Project: kick note</li>
 * <li>Package: /app/component/AccountComponent</li>
 * <li>Description: Component of account use for create  </li>
 * <li>Copyright: Copyright (c) 2008</li>
 * <li>Company: Infolex LLC </li>
 * <li>Created on 2008-5-28</li>
 *
 * @author lei_gao
 * @version 1.0
 */
require_once(APP.'libs'.DS.'system_properties.php');
class AccountComponent extends Object {
	function startup (&$controller)
	{
		$this->controller=&$controller;
		$this->user = ClassRegistry::init('User');
		
	}
	function getNowTime(){
		$sql="SELECT now();";
		$data=$this->user->query($sql);
		$time=$data[0][0]['now()'];
		return $time;
	}
	function getZeroTimeOfDate(){
		return	date("Y-m-d",strtotime($this->getNowTime()));
	}
	
	function findUser($g_id){
		return $this->user->find(array('User.g_id'=>$g_id));
	}
	
	function updateUserMoney($g_id,$moneys){
		$sql="update g_users g set g.g_money=$moneys where g.g_id=$g_id" ;
		$this->user->query($sql);
	}
	
	function updateUser($g_id,$moneys,$experience,$level){
		if($moneys!=0){
			$sql="update g_users g set g.g_money=g.g_money+$moneys where g.g_id=$g_id" ;
			$this->user->query($sql);
		}
		if($experience!=0){
			$sql="update g_users g set g.g_experience=g_experience+$experience where g.g_id=$g_id" ;
			$this->user->query($sql);
		}

		if($level!=0){
			$sql="update g_users g set g.g_level=$level where g.g_id=$g_id" ;
			$this->user->query($sql);
		}

	}

}
?>